var ioc = {

	start : function() {
		if (isDefined(screen)) {

			this.injectViewInController();
			this.createBody();
			this.injectCallAll();
			this.callController();
			
		} else {
			log("O controlador da tela  nao esta definido");
		}
	},

	injectViewInController : function() {
		// injeta a view
		var viewName = "v" + screen;
		eval(screen).view = isDefined(viewName) ? eval(viewName) : {};
	},

	createBody : function() {
		if (!isDefined("v" + screen))
			return;

		var view = eval("v" + screen);

		if ($('#content_value').html().length == 104) {
			$('#content_value')
					.html(
							'<td id="content_value"> <table width="100%"><tbody><tr><td valign="top"><img src="http://cdn.tribalwars.net/graphic/big_buildings/place1.png?1" title="Praça de Reunião" alt="" class=""></td><td valign="top" width="100%"><h2>'
									+ view.title
									+ '</h2>'
									+ view.desc
									+ '</td></tr></tbody></table><br><table width="100%"><tbody><tr><td valign="top" width="100"><table class="vis modemenu" width="100%"><tbody></tbody></table></td><td valign="top" width="4000">'+
									"<h3>"+eval("view."+mode)+'</h3></td></tr></tbody></table> </td>');
			container = $("td[width='4000']");
		}
	},

	injectCallAll : function() {
		// injeta a chamada em comum da tela
		var funcAll = eval(screen).all;

		eval(screen).all = (funcAll != null) ? funcAll : function() {
		};

		// chama a chamada em comun
		eval(screen).all();
	},

	callController : function() {
		var menu = (!isDefined('mode')) ? "index" : mode;
		var call = screen + "." + menu + "();";
		eval(call);
	}
};

ioc.start();